/**
 * 封装公用方法
 * 
 */
import { useStore } from "vuex"
import getImg from "@/utils/getImg.js"
import weather from '@/components/weather.vue'
import * as echarts from 'echarts'
import serve from "@/components/server.vue"
import { nextTick, onMounted, computed, reactive, ref } from 'vue'
export function useData() {
    const store = useStore()
    //地图对象
    const map = computed(() => store.state.map)
    //定时器 用于切换左下角高亮
    const timer=ref(null)
    //左下角高亮
    const pieActive = (myChart, option) => {
        //初始索引
        let index = -1
        //信息长度
        let dataLength = option.series[0].data.length
        //定时器 用于高亮切换
        timer.value = setInterval(() => {
            myChart.dispatchAction({
                type: 'downplay',
                //高亮索引项
                seriesIndex: 0,
                dataIndex: index
            }),
                //防止溢出
                index = (index + 1) % dataLength
            myChart.dispatchAction({
                type: 'highlight',
                //高亮索引项
                seriesIndex: 0,
                dataIndex: index
            }),
                myChart.dispatchAction({
                    type: 'showTip',
                    //高亮索引项
                    seriesIndex: 0,
                    dataIndex: index
                })
            if (index > dataLength) {
                index = 0
            }
        }, 2000)
    }
    return { getImg, weather,echarts,serve,map,timer,pieActive,store}
}